package com.xjtu.chapter08.thread;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/30 10:24
 */
class JoinThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i <5 ; i++) {
            System.out.println("Join thread is running");
        }
    }
}
public class JoinTest {
    public static void main(String[] args) {
        System.out.println("in main thread");
        JoinThread joinThread = new JoinThread();
        joinThread.start();
        try {
            System.out.println("join status is: "+joinThread.isAlive());
            joinThread.join();//joinThread加入到主线程
            System.out.println("after join, joined thread exits");
            System.out.println("join status is: "+joinThread.isAlive());
        } catch (InterruptedException e) {
            System.out.println(e);
            System.out.println("join thread is dead");
        }
        System.out.println("main thread is still running");
    }
}
